package newcall.com.newcalldemo;

import android.util.Log;

import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class TimeUtis {

    private static TimeUtis  instance;
    public static TimeUtis getInstance() {
        if (instance==null)
        {
            instance=new TimeUtis();
        }
        return instance;
    }


    //获取指定时间的  星期几  几号
    public DateItemDTO getCustomDate(Date date){
        final Calendar c = Calendar.getInstance();
        c.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
        c.setTime(date);
        String mYear = String.valueOf(c.get(Calendar.YEAR)); // 获取当前年份
        String mMonth = String.valueOf(c.get(Calendar.MONTH) + 1);// 获取当前月份
        String mDay = String.valueOf(c.get(Calendar.DAY_OF_MONTH));// 获取当前月份的日期号码
        String mWay = String.valueOf(c.get(Calendar.DAY_OF_WEEK));
        if ("1".equals(mWay)) {
            mWay = "日";
        } else if ("2".equals(mWay)) {
            mWay = "一";

        } else if ("3".equals(mWay)) {
            mWay = "二";

        } else if ("4".equals(mWay)) {
            mWay = "三";

        } else if ("5".equals(mWay)) {
            mWay = "四";

        } else if ("6".equals(mWay)) {
            mWay = "五";

        } else if ("7".equals(mWay)) {
            mWay = "六";
        }
        Log.d("test", "getCurrentTime: "+mYear + "年" + mMonth + "月" + mDay + "日" + "/星期" + mWay);

        DateItemDTO d = new DateItemDTO();
        d.setData(date);
        d.setWeek("周"+mWay);
        d.setDay(mDay);
        return  d;
    }
    public  Date getCurrentTime() {

        //获取当前时间
        Date date = new Date(System.currentTimeMillis());
        return date;
    }

    /**
     *
     * @param beginTime 开始时间
     * @param Day 从开始时间  相隔 day 天数 的 时间数据  （可以负数）
     * @return
     */
    public Date getSpaceTime(Date beginTime,int Day){

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(beginTime);
        calendar.add(Calendar.DATE, Day);
        Date date = calendar.getTime();
        return date;
    }



}
